package 多线程02_常见线程方法;

import 多线程01_启动线程.Hero;

/**
 * @ClassName: TestThreadJoin
 * @Author: AllenSun
 * @Date: 2022/3/18 下午8:37
 */
public class TestThreadYield {
    public static void main(String[] args) {
        Hero gareen = new Hero("盖伦",616,100);
        Hero teemo = new Hero("提莫",300,130);
        Hero bh = new Hero("赏金猎人",350,165);
        Hero leesin = new Hero("盲僧",455,180);

        Thread t1= new Thread(){
            public void run(){

                while(!teemo.isDead()){
                    gareen.attactHero(teemo);
                }
            }
        };

        Thread t2= new Thread(){
            public void run(){
                while(!leesin.isDead()){
                    //临时暂停，使得t1可以占用CPU资源
                    Thread.yield();

                    bh.attactHero(leesin);
                }
            }
        };

        t1.setPriority(5);
        t2.setPriority(5);
        t1.start();
        t2.start();
    }
}
